<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改部门')"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-dept-edit">
        <input id="flagInt" name="flagInt" type="hidden" value="0"/>
        <input id="flagString" name="flagString" type="hidden" value=""/>
        <input id="spareInt" name="spareInt" type="hidden" value="0"/>
        <input id="spareString" name="spareString" type="hidden" value=""/>
        <input id="treeId" name="noParent" type="hidden" th:value="${parentName.noUnit}"/>

        <div class="form-group">
            <label class="col-sm-3 control-label">上级部门：</label>
            <div class="col-sm-8">
                <div class="input-group">
                    <input class="form-control" type="text" onclick="selectDeptTree()" id="treeName" readonly="true"
                           th:value="${parentName.deptName}">
                    <span class="input-group-addon"><i class="fa fa-search"></i></span>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">部门ID：</label>
                    <div class="col-sm-8">
                        <input name="noUnit" th:value="${dept.noUnit}"  placeholder="请输入部门ID" class="form-control" type="text" maxlength="30" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">单位名称：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input name="deptName" th:value="${dept.deptName}" id="deptName" required   type="text" placeholder="单位名称" class="form-control">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label is-required">自编号：</label>
                    <div class="col-sm-8">
                        <input name="noSelf" th:value="${dept.noSelf}" placeholder="请输入自编号" class="form-control" type="text" maxlength="30" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">部门缩写：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input name="deptSx" th:value="${dept.deptSx}"  type="text" placeholder="部门缩写" class="form-control">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label ">部门别称：</label>
                    <div class="col-sm-8">
                        <input name="deptShort" th:value="${dept.deptShort}" placeholder="请输入部门别称" class="form-control" type="text" maxlength="30" >
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">排序值：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input name="ordNum" th:value="${dept.ordNum}"   type="text" placeholder="排序值" class="form-control">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label ">行政区划：</label>
                    <div class="col-sm-8">
                        <input type="hidden" id="areaName" name="areaName" th:value="${dept.areaName}">
                        <select name="areaNo" id="areaNo" required
                                th:with="area=${@commonServiceImpl.findArea()}"
                                onchange="dropChgSendTextOnly(this,'areaName');"
                                class="form-control formSelect">
                            <option value="-1">--请选择--</option>
                            <option value="5101" th:selected="${dept.areaNo == '5101'}">成都市</option>
                            <th:block th:each="item : ${area}">
                                <option th:text="${item['CSText']}" th:value="${item['CSValue']}" th:selected="${item['CSValue']==dept.areaNo}"></option>
                            </th:block>
                            <option value="909909" th:selected="${dept.areaNo == '909909'}">其它</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">行政序列：</label>
                    <div class="col-sm-8">
                        <input type="hidden" id="kind" th:value="${dept.kindCode}">
                        <select style="border-radius: 4px;border: 1px solid #ddd;padding-left: 10px;height: 30px" id="kindCode" name="kindCode" class="drpCss">
                            <option value="-1">-请选择-</option>
                            <option value="11" th:selected="${dept.kindCode == '11'}">党委</option>
                            <option value="21" th:selected="${dept.kindCode == '21'}">政府</option>
                            <option value="61" th:selected="${dept.kindCode == '61'}">事业单位</option>
                            <option value="62" th:selected="${dept.kindCode == '62'}">垂直机构</option>
                            <option value="71" th:selected="${dept.kindCode == '71'}">民主党派和工商联</option>
                            <option value="72" th:selected="${dept.kindCode == '72'}">群众团体</option>
                            <option value="91" th:selected="${dept.kindCode == '91'}">system</option>
                            <option value="92" th:selected="${dept.kindCode == '92'}">外包坐席</option>
                            <option value="99" th:selected="${dept.kindCode == '99'}">其它</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label ">主管领导：</label>
                    <div class="col-sm-8">
                        <input th:value="${dept.nameMaster}" name="nameMaster" placeholder="请输入主管领导" class="form-control" type="text" maxlength="30" >
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">分管领导：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input th:value="${dept.nameFinance}" name="nameFinance"   type="text" placeholder="分管领导" class="form-control">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label ">联系手机：</label>
                    <div class="col-sm-8">
                        <input th:value="${dept.phoneNO}" name="phoneNO" placeholder="请输入联系手机" class="form-control" type="text" maxlength="30" >
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">联系方式：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input th:value="${dept.contactWay}" name="contactWay"   type="text" placeholder="联系方式" class="form-control">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">部门简介：</label>
                    <div class="col-xs-10">
                        <textarea  name="deptDesc" th:field="*{dept.deptDesc}" maxlength="500" class="form-control" rows="3"></textarea>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <label class="col-xs-2 control-label">备注：</label>
                    <div class="col-xs-10">
                        <textarea  name="remark" th:field="*{dept.remark}" maxlength="500" class="form-control" rows="3"></textarea>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label">部门状态：</label>
            <div class="col-sm-8">
                <div class="radio-box">
                    <input type="radio" name="useState" value="1"
                           th:checked="${dept.useState == 1}">
                    <label>启用</label>
                </div>
                <div class="radio-box">
                    <input type="radio" name="useState" value="0" th:checked="${dept.useState == 0}">
                    <label>停用</label>
                </div>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<script type="text/javascript">
    var prefix = ctx + "system/dept";

    $("#form-dept-edit").validate({
        onkeyup: false,
        rules: {
            deptName: {
                remote: {
                    url: prefix + "/checkDeptNameUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        "deptId": function () {
                            return $("#deptId").val();
                        },
                        "parentId": function () {
                            return $("input[name='parentId']").val();
                        },
                        "deptName": function () {
                            return $.common.trim($("#deptName").val());
                        }
                    },
                    dataFilter: function (data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
            order_num: {
                digits: true
            },
            email: {
                email: true,
            },
            phone: {
                isPhone: true,
            },
        },
        messages: {
            "deptName": {
                remote: "部门已经存在"
            }
        },
        focusCleanup: true
    });

    function submitHandler() {
        if ($.validate.form()) {
            $.operate.save(prefix + "/edit", $('#form-dept-edit').serialize());
        }
    }

    /*部门管理-修改-选择部门树*/
    function selectDeptTree() {
        var deptId = $("#treeId").val();
        var excludeId = $("input[name='deptId']").val();
        if (deptId > 0) {
            var options = {
                title: '部门选择',
                width: "380",
                url: prefix + "/selectDeptTree/" + $("#treeId").val() + "/" + excludeId,
                callBack: doSubmit
            };
            $.modal.openOptions(options);
        } else {
            $.modal.alertError("父部门不能选择");
        }
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowLastLevel(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
    function DropChgSendTextOnly(e,acpId) {
        document.getElementById(acpId).value = e.options[e.selectedIndex].text;
    }
</script>
</body>
</html>
